n = int(input())
if (n < 1000) or (n > 9999):
  print(0)
else:
   n1 = str(n//1000%10)
   n2 = str(n//100%10)
   n3 = str(n//10%10)
   n4 = str(n//1%10)
   spis = [int(n1), int(n2), int(n3), int(n4), int(n1+n2), int(n1+n2+n3), int(n1+n2+n3+n4), int(n2+n3), int(n2+n3+n4), int(n3+n4)]
   spis.sort()
   spis = spis[::-1]

for x in spis:
  F = 1
  for d in range(2, x//2+1):
   if x % d == 0:
    F = 0
    break
  if F==1:
    print(x)
    break
  if F==0:
    print('0')
else:print('0')
